package com.aat.dxfy.web.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.aat.dxfy.web.utils.WebConstant;

@WebListener
public class ThisHttpSessionFilter implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		HttpSession ses = event.getSession();
		String id = ses.getId() + ses.getCreationTime();
		WebConstant.UserMap.put(id, Boolean.TRUE); // 添加用户
		WebConstant.USERNUM++;
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		HttpSession ses = event.getSession();
		String id = ses.getId() + ses.getCreationTime();
		synchronized (this) {
			WebConstant.USERNUM--; // 用户数减一
			WebConstant.UserMap.remove(id); // 从用户组中移除掉，用户组为一个map
		}
	}

}
